﻿<%@ WebHandler Language="C#" Class="SYS_Product_update" %>

using System;
using System.Web;
using System.Web.Script.Serialization;
using System.Collections.Generic;
using System.Web.SessionState;

public class SYS_Product_update : IHttpHandler,IRequiresSessionState {
    sqlhelp sql = new sqlhelp();
    result result = new result();
    string str = "";
    public void ProcessRequest (HttpContext context) {
        try
        {
            if (context.Session["comid"] == null)
            {
                result.code = "-1";
                result.msg = "用户未登录";
                unit.send(context, result);
                return;
            }
            
            string updateStr = "";
            string Id = "";
            if (context.Request["Id"] != null)
            {
                Id = context.Request["Id"].ToString();
            }
            else {
                result.code = "0";
                result.msg = "未传递Id参数";
                unit.send(context, result);
                return;
            }
            string CategoryId = ""; 
            if (context.Request["CategoryId"] != null) { 
                CategoryId = context.Request["CategoryId"].ToString();
                updateStr = updateStr + " CategoryId = '" + CategoryId + "',";
            } 
            string Title = ""; 
            if (context.Request["Title"] != null) { 
                Title = context.Request["Title"].ToString();
                updateStr = updateStr + " Title = '" + Title + "',";
            }
            string BannerId = "";
            if (context.Request["BannerId"] != null)
            {
                BannerId = context.Request["BannerId"].ToString();
                updateStr = updateStr + " BannerId = '" + BannerId + "',";
            }
            string DetailImgId = "";
            if (context.Request["DetailImgId"] != null)
            {
                DetailImgId = context.Request["DetailImgId"].ToString();
                updateStr = updateStr + " DetailImgId = '" + DetailImgId + "',";
            } 
            string SubTitle = ""; 
            if (context.Request["SubTitle"] != null) { 
                SubTitle = context.Request["SubTitle"].ToString();
                updateStr = updateStr + " SubTitle = '" + SubTitle + "',";
            } 
            string AveragePrice = ""; 
            if (context.Request["AveragePrice"] != null) { 
                AveragePrice = context.Request["AveragePrice"].ToString();
                updateStr = updateStr + " AveragePrice = '" + AveragePrice + "',";
            } 
            string Price = ""; 
            if (context.Request["Price"] != null) { 
                Price = context.Request["Price"].ToString();
                updateStr = updateStr + " Price = '" + Price + "',"; 
            } 
            string ActivityPrice = ""; 
            if (context.Request["ActivityPrice"] != null) { 
                ActivityPrice = context.Request["ActivityPrice"].ToString();
                updateStr = updateStr + " ActivityPrice = '" + ActivityPrice + "',"; 
            }
            string DetailText = "";
            if (context.Request["DetailText"] != null)
            {
                DetailText = context.Request["DetailText"].ToString();
                updateStr = updateStr + " DetailText = '" + DetailText + "',";  
            }
            string Cover = "";
            if (context.Request["Cover"] != null)
            {
                Cover = context.Request["Cover"].ToString();
                updateStr = updateStr + " Cover = '" + Cover + "',";  
            }
            string CreateTime = ""; 
            if (context.Request["CreateTime"] != null) { 
                CreateTime = context.Request["CreateTime"].ToString();
                updateStr = updateStr + " CreateTime = '" + CreateTime + "',";  
            } 
            string Enable = ""; 
            if (context.Request["Enable"] != null) { 
                Enable = context.Request["Enable"].ToString();
                updateStr = updateStr + " Enable = " + Enable + ",";  
            }
            if (updateStr == "")
            {
                result.code = "0";
                result.msg = "未传递修改参数";
                unit.send(context, result);
                return;
            }

            updateStr = updateStr.TrimEnd(',');

            str = "update SYS_Product set " + updateStr + " where Id = '" + Id + "'"; 
            
            if (sql.ExecuteNonQuery(str) > 0)
            {
                result.code = "1";
                result.msg = "";
            }
            else
            {
                result.code = "0";
                result.msg = "修改失败";
            }

        }
        catch (Exception e1)
        {
            result.code = "0";
            result.msg = e1.Message;
        }
        unit.send(context, result);
    }

    public bool IsReusable {
        get {
            return false;
        }
    }

}
